var pathRequestUrl;

Ext.onReady(function(){
    Ext.QuickTips.init();
    pathRequestUrl = 'ReportNerverExchanged_Data.php';
    
    var partnerRecord = [{
        name: 'partner_id',
        type: 'string'
    }, {
        name: 'partner_number',
        type: 'string'
    }, {
        name: 'partner_name',
        type: 'string'
    }];
    
    var partnerObj = Ext.data.Record.create(partnerRecord);
    
    var storePartner = new Ext.data.Store({
        reader: new Ext.data.JsonReader({
            root: 'data',
            totalProperty: 'count',
            id: 'partner_id'
        }, partnerObj),
        proxy: new Ext.data.HttpProxy({
            url: pathRequestUrl
        }),
        autoLoad: true
    });
    
    storePartner.on('beforeload', function(){
        storePartner.baseParams.action = 'getPartner';
    });
    
    var cbSubjectName = new Ext.form.ComboBox({
        id: 'cbSubjectName',
        name: 'cbSubjectName',
        store: storePartner,
        fieldLabel: 'Đối tác',
        forceSelection: true,
        displayField: 'partner_name',
        valueField: 'partner_id',
        allowBlank: false,
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText: 'Chọn đối tác',
        selectOnFocus: true,
        editable: false,
        width: 300,
        minListWidth: 300,
        lazyRender: true
    });
	
    var generalTab = new Ext.Panel({
        frame: true,
        title: '',
        //height: 260,
        id: 'generalTab',
        items: [{
            layout: 'form',
            labelWidth: 100,
            items: [{
                xtype: 'fieldset',
                title: 'Đối tác',
                autoHeight: true,
                items: [cbSubjectName]
            }]
        }]
    });
    
    var dataSinger = new Ext.FormPanel({
        frame: true,
        title: 'Bảng danh sách các bài hát chưa từng có sản lượng',
        width: 550,
        renderTo: 'ReportNeverExchangedTables',
        iconCls: 'form-icon',
        url: pathRequestUrl,
        fileUpload: true,
        items: [generalTab],
        buttons: [{
            text: 'In báo cáo',
            handler: function(){
                if (dataSinger.getForm().isValid()) {
                    window.open(pathRequestUrl + '?action=export' +
				'&partnerId=' + Ext.getCmp('cbSubjectName').getValue(), null, 
                    		'height=900,width=900,status=yes,toolbar=no,menubar=no,location=no');
                }
            }
        }, {
            text: 'Thoát'
        }]
    });
});
